Previous Thread
Next Thread
Print Thread
Rate Thread
#248229 05/27/2003 11:24 PM
Joined: Nov 2001
Posts: 10,369
I type Like navaho
I type Like navaho
Joined: Nov 2001
Posts: 10,369
I usually use an .htaccess file like this to password protect directories.

[]
AuthUserFile /home/blah/blah/lunch/blah/.htpasswd
AuthGroupFile /dev/null
AuthName "phpProtection"
AuthType Basic

<Limit GET POST>
require valid-user
</Limit>[/]

Can you use .htaccess to password protect only a single file? Or does it always have to be a whole directory?

Sponsored Links
Joined: Feb 2002
Posts: 2,286
Veteran
Veteran
Joined: Feb 2002
Posts: 2,286
AFAIK - it a directory level thing only - I suppose you could put that file in a unique directory and then in htaccess redirect anyone viewing that file, to the one in the unique directory - that way the one file would be passworded, simply because the entire directory is.

Havn't tried it, but that ought to work.



Fans Focus - Focusing on Fans of Sport

(Okay - mainly football (the British variety wink at the moment - but expanding all the time....)
Joined: Feb 2002
Posts: 1,759
Addict
Addict
Offline
Joined: Feb 2002
Posts: 1,759
Ian is correct, I don't think you can password protect an individual file, at least not with .htaccess I don't think. The only real restrictions you can put on files by default is by CHMOD, but when restricting a file that way, you will either allow or dissalow permission, there is no password prompt.

If someone knows of a way to do this, it would be good to know. But I think CHMOD will restrict files too much, and .htaccess will only work on a directory level.

Joined: Oct 2000
Posts: 2,222
Veteran
Veteran
Offline
Joined: Oct 2000
Posts: 2,222
Sure, why not.

Stick this in your httpd.conf in your virtual host container. It will probably work with an .htaccess too.

<Files /path/to/myfile.php>
AuthUserFile /home/blah/blah/lunch/blah/.htpasswd
AuthGroupFile /dev/null
AuthName "phpProtection"
AuthType Basic

<Limit GET POST>
require valid-user
</Limit>
</Files>

What I can't remember is ... is it <Files or <File



Picture perfect penmanship here.
Joined: Nov 2001
Posts: 10,369
I type Like navaho
I type Like navaho
Joined: Nov 2001
Posts: 10,369
Navaho - once again - you are my hero.

It is "files" and did work in .htaccess

The only difference was that since I was putting the .htaccess file in the directory that the file was in - I didn't need the whole path in the first line - just the filename.

Then it worked like a charm.

Thank you!!!!!!

Sponsored Links
Joined: Oct 2000
Posts: 2,222
Veteran
Veteran
Offline
Joined: Oct 2000
Posts: 2,222


Picture perfect penmanship here.
Joined: Nov 2001
Posts: 10,369
I type Like navaho
I type Like navaho
Joined: Nov 2001
Posts: 10,369




Joined: Feb 2002
Posts: 2,286
Veteran
Veteran
Joined: Feb 2002
Posts: 2,286
Might want to move this to Design Matters - as it is a very useful tip Thanks Navaho.

Of course Jeremy & I knew this - but want to test Navaho's knowledge...... I wish!!


Fans Focus - Focusing on Fans of Sport

(Okay - mainly football (the British variety wink at the moment - but expanding all the time....)
Joined: Feb 2002
Posts: 1,759
Addict
Addict
Offline
Joined: Feb 2002
Posts: 1,759
haha.. yeah, really I was just testing rick's skills But no.. I had no idea you could do that, so I have added it to my list of useful information

Joined: Nov 2003
Posts: 1
Lurker
Lurker
Joined: Nov 2003
Posts: 1
very interesting...but I have a "little" question.
What do I have to write in .htaccess file?
Regards from Spain.
Details:
I use windows millenium and I have to protect ONLY one file called admin.php located in folder SITIO56.
In SITIO56 there are more files, but I only want to protect admin.php.

Last edited by marylin77; 11/02/2003 3:55 PM.
Sponsored Links

Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Shock Hosting
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
Gizmo
Gizmo
Portland, OR, USA
Posts: 5,834
Joined: January 2000
Forum Statistics
Forums63
Topics37,583
Posts293,955
Members13,824
Most Online151,614
Nov 14th, 2025
Today's Statistics
Currently Online 4888
Topics Created 0
Posts Made 0
Users Online 0
Birthdays 29
Top Posters
AllenAyres 21,080
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,834
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2026 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.1.0
(Snapshot build 20260108)